{include file="my/header"}
<div class="container-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <!-- 表格数据查询块 -->
            <!-- <div class="table-query">
                <form class="layui-form layui-inline J-search-form" action="">
                    <div class="layui-inline">
                        <label class="layui-form-label">搜索ID：</label>
                        <div class="layui-inline">
                            <input class="layui-input J-query-params" name="id" autocomplete="off" placeholder="请输入id" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">课程:</label>
                        <div class="layui-inline">
                            <input class="layui-input J-query-params" name="coursename" autocomplete="off" placeholder="请输入课程" />
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">考试任务:</label>
                        <div class="layui-inline">
                            <input class="layui-input J-query-params" name="name" autocomplete="off" placeholder="请输入内容" />
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">审核状态:</label>
                        <div class="layui-inline">
                            <select name="check" class="layui-input J-query-params">
                                <option value="" selected>请选择审核状态</option>
                                <option value="0">未审核</option>
                                <option value="1">已通过</option>
                                <option value="2">未通过</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">发布时间:</label>
                        <div class="layui-inline">
                            <input type="text" class="layui-input J-query-params J-date" name="create_time" placeholder="yyyy-MM-dd" />
                        </div>
                    </div>
                </form>
                <button class="layui-btn J-search" data-type="reload">搜索</button>
                <button class="layui-btn J-reload">重置</button>
            </div> -->
            <!-- 表格 -->
            <table class="layui-hide" id="testTable" lay-filter="tableOption"></table>

            <!-- 表格工具 -->
            <script type="text/html" id="toolbarDemo"></script>
            <script type="text/html" id="barDemo">
                {if session('userclass') == '1'} {{# if(d.check1 != 0){ }}
                <a class="layui-btn layui-btn-xs layui-btn-normal">已审核</a>
                {{# } else { }}
                <a class="layui-btn layui-btn-xs" lay-event="check">审核</a>
                {{# } }} {elseif session('userclass') == '2' /} {{# if(d.check2 != 0){ }}
                <a class="layui-btn layui-btn-xs layui-btn-normal">已审核</a>
                {{# } else { }}
                <a class="layui-btn layui-btn-xs" lay-event="check">审核</a>
                {{# } }} {elseif session('userclass') == '3' /} {{# if(d.check3 != 0){ }}
                <a class="layui-btn layui-btn-xs layui-btn-normal">已审核</a>
                {{# } else { }}
                <a class="layui-btn layui-btn-xs" lay-event="check">审核</a>
                {{# } }} {/if}

                <!-- <a class="layui-btn layui-btn-xs" lay-event="check">审核</a> -->
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
        </div>

        <!-- 弹出模板框 -->
        <div class="margin-top30 J-temple is-hidden">
            <form class="layui-form layui-fluid J-add-form" lay-filter="formTest">
                <input type="hidden" class="form-control" name="scoreid" value="" placeholder="请输入内容" />
                <input type="hidden" class="form-control" name="id" value="" placeholder="请输入内容" />
                <input type="hidden" class="form-control" id="schoolid" name="schoolid" value="99" placeholder="请输入内容" />
                <div class="layui-form-item">
                    <label class="layui-form-label">原成绩</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" name="oldscore" placeholder="请输入内容" />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">修改后成绩</label>
                    <div class="layui-input-block">
                        <input type="text" class="layui-input" name="newscore" id="newscore" placeholder="请输入内容" />
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">学生</label>
                    <div class="layui-input-block">
                        <select name="studentid" id="studentid">
                            {volist name='studentsData' id='studentsData'}
                            <option value="{$studentsData.id}">{$studentsData.studentname}</option>
                            {/volist}
                        </select>
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">申请事项</label>
                    <div class="layui-input-block">
                        <textarea name="applyitem" placeholder="请输入内容" class="layui-textarea"></textarea>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">授课老师</label>
                    <div class="layui-input-block">
                        <select name="teacherid" id="teacherid">
                            {volist name='teacherinfodata' id='teacherinfodata'}
                            <option value="{$teacherinfodata.teacherid}">{$teacherinfodata.teachername}</option>
                            {/volist}
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">老师理由</label>
                    <div class="layui-input-block">
                        <textarea name="change_reason" placeholder="请输入内容" class="layui-textarea"></textarea>
                    </div>
                </div>

                <div class="layui-form-item layui-form-text J-upload">
                    <label class="layui-form-label">证明文件</label>
                    <div class="layui-upload">
                        <button type="button" class="layui-btn layui-btn-normal" id="test8">选择文件</button>
                        <button type="button" class="layui-btn" id="test9">开始上传</button>
                        <label class="J-file-name"></label>
                        <input type="hidden" name="verify_file" class="J-verify-file" />
                    </div>
                </div>

                <div class="layui-form-item layui-form-text J-download">
                    <label class="layui-form-label">证明文件</label>
                    <div class="layui-input-block">
                        <label class="J-file-name"></label>
                        <a href="#" class="blue J-verify-file">点击下载</a>
                        <!-- <input type="hidden" name="verify_file" id="verifyFile" /> -->
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

<script>
    $(function () {
        initClass('courselist');
        var userClass = getCookie('userClass');
        // if (userClass == 3)
        initTable();
        layuiDate('.J-date');
        if (getCookie('userClass') == 3) {
            $('.J-upload').show();
            $('.J-download').hide();
        } else {
            $('.J-upload').hide();
            $('.J-download').show();
        }
    });

    function initTable() {
        var table;

        // 请求路径
        var requireUrl = {
            add: "{:url('score/result_input_add')}",
            check: "{:url('score/modify_check')}",
            remove: "{:url('score/modify_remove')}",
            list: "{:url('score/get_modify_list')}",
            upload: "{:url('score/verify_file_upload')}",
            download: "{:url('score/download_file')}",
        };

        layui.use('table', function () {
            table = layui.table;
            table.render({
                elem: '#testTable',
                url: requireUrl.list,
                toolbar: '#toolbarDemo',
                title: '成绩修改审批',
                totalRow: false,
                cols: [
                    [
                        {
                            type: 'checkbox',
                            fixed: 'left',
                            align: 'center',
                            // minWidth: '50',
                        },
                        {
                            field: 'id',
                            title: 'ID',
                            align: 'center',
                            // minWidth: '50',
                        },
                        {
                            field: 'oldscore',
                            title: '原成绩',
                            align: 'center',
                            minWidth: '80',
                        },
                        {
                            field: 'newscore',
                            title: '修改后成绩',
                            align: 'center',
                            minWidth: '100',
                        },
                        {
                            field: 'studentname',
                            title: '学生',
                            align: 'center',
                            minWidth: '100',
                        },
                        {
                            field: 'applyitem',
                            title: '申请事项',
                            align: 'center',
                            minWidth: '200',
                            // templet: function (d) {
                            //     var result;
                            //     if (d.result == 0) result = '<span class="green">正常</span>';
                            //     if (d.result == 1) result = '<span class="red">缺考</span>';
                            //     if (d.result == 2) result = '<span class="red">作弊</span>';
                            //     return result;
                            // }
                        },
                        {
                            field: 'teachername',
                            title: '授课老师',
                            align: 'center',
                            minWidth: '100',
                        },
                        {
                            field: 'change_reason',
                            title: '老师理由',
                            align: 'center',
                            minWidth: '200',
                        },
                        {
                            field: 'verify_file',
                            title: '证明文件',
                            align: 'center',
                            minWidth: '120',
                            templet: d => {
                                return '<a href="' + d.verify_file + '" class="blue">下载</a>';
                            },
                        },
                        {
                            field: 'check3',
                            title: '教师审核',
                            align: 'center',
                            minWidth: '100',
                            templet: d => {
                                var result;
                                d.check3 == 0 && (result = '<span class="">未审核</span>');
                                d.check3 == 1 && (result = '<span class="green">通过</span>');
                                d.check3 == 2 && (result = '<span class="red">不通过</span>');
                                return result;
                            },
                        },
                        {
                            field: 'check1',
                            title: '学院审核',
                            align: 'center',
                            minWidth: '100',
                            templet: d => {
                                var result;
                                d.check1 == 0 && (result = '<span class="">未审核</span>');
                                d.check1 == 1 && (result = '<span class="green">通过</span>');
                                d.check1 == 2 && (result = '<span class="red">不通过</span>');
                                return result;
                            },
                        },
                        {
                            field: 'check2',
                            title: '教务审核',
                            align: 'center',
                            minWidth: '100',
                            templet: d => {
                                var result;
                                d.check2 == 0 && (result = '<span class="">未审核</span>');
                                d.check2 == 1 && (result = '<span class="green">通过</span>');
                                d.check2 == 2 && (result = '<span class="red">不通过</span>');
                                return result;
                            },
                        },
                        {
                            field: 'create_time',
                            title: '创建时间',
                            align: 'center',
                            minWidth: '120',
                        },
                        {
                            fixed: 'right',
                            title: '操作',
                            toolbar: '#barDemo',
                            width: 140,
                        },
                    ],
                ],
                id: 'testReload',
                page: true,
                parseData: function (res) {
                    return {
                        code: 0,
                        msg: '',
                        count: res.length,
                        data: res,
                    };
                },
            });

            //监听行工具事件
            table.on('tool(tableOption)', function (obj) {
                var data = obj.data;
                switch (obj.event) {
                    case 'del':
                        layerConfirm(requireUrl.remove, {
                            id: data.id,
                        });
                        break;

                    case 'check':
                        // 修改成绩审核
                        var data = {
                            id: data.id,
                        };
                        var buttonConfig = {
                            title: '审核',
                            btnTitle: ['通过', '不通过'],
                        };
                        layerOpenInit(
                            buttonConfig,
                            $('.J-temple'),
                            function (index) {
                                // 通过操作
                                var formData = $('.J-add-form').serialize();
                                formData += '&check=1';
                                ajaxRequest('post', requireUrl.check, formData, function (data) {
                                    data.code == 1 ? successTrip(data) : errorAlert(false, data.msg);
                                });
                            },
                            function () {
                                // 弹出后的回调
                                ajaxRequest('get', requireUrl.check, { id: data.id }, function (res) {
                                    form.val('formTest', res.data);
                                    $('.J-verify-file').prop('href', res.data.verify_file);
                                });

                                //选完文件后不自动上传
                                upload.render({
                                    elem: '#test8',
                                    url: requireUrl.upload, //改成您自己的上传接口
                                    auto: false,
                                    //,multiple: true
                                    bindAction: '#test9',
                                    accept: 'file',
                                    choose: function (obj) {
                                        //将每次选择的文件追加到文件队列
                                        var files = obj.pushFile();
                                        //预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
                                        obj.preview(function (index, file, result) {
                                            console.log(index); //得到文件索引
                                            console.log(file.name); //得到文件对象
                                            // console.log(result); //得到文件base64编码，比如图片
                                            $('.J-file-name').text(file.name);
                                        });
                                    },
                                    done: function (res) {
                                        layer.msg('上传成功');
                                        console.log(res);
                                        $('.J-verify-file').val(res.msg);
                                    },
                                });
                            },
                            function (index) {
                                // 不通过
                                var formData = $('.J-add-form').serialize();
                                formData += '&check=2';
                                ajaxRequest('post', requireUrl.check, formData, function (data) {
                                    data.code == 1 ? successTrip(data) : errorAlert(false, data.msg);
                                });
                            }
                        );
                        break;
                }
            });
        });

        // 搜索重置操作
        var active = {
            reload: function () {
                var queryParams = serializeObject($('.J-search-form'));
                console.log(queryParams);
                //执行重载
                table.reload(
                    'testReload',
                    {
                        page: {
                            curr: 1, //重新从第 1 页开始
                        },
                        where: queryParams,
                    },
                    'data'
                );
            },
        };
        $('.J-search').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $('.J-reload').on('click', function () {
            $('.J-query-params').val('');
            form.render('select');
            active.reload ? active.reload.call(this) : '';
        });
    }
</script>

{include file="my/footer"}
